package com.formula.propertyshop.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.formula.propertyshop.R;
import com.formula.propertyshop.model.BSDPropertyType;

public class BSDPropertyTypeSpinnerAdapter extends ArrayAdapter<BSDPropertyType>{

	private Context context;
	private List<BSDPropertyType>pType;
	public BSDPropertyTypeSpinnerAdapter(Context context, int textViewResourceId,
			List<BSDPropertyType> objects) {
		super(context, textViewResourceId, objects);
		this.context = context;
		this.pType = objects;
	}

	public int getCount() {
		return pType.size();
	}

	public BSDPropertyType getItem(int position) {
		return pType.get(position);
	}

	public long getItemId(int position) {
		return position;
	}
	// And the "magic" goes here
    // This is for the "passive" state of the spinner
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        
        LayoutInflater inflater = 
	              (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if(convertView == null){
			convertView = inflater.inflate(R.layout.spinner_item, parent,false);
			((TextView)convertView).setText(pType.get(position).toString());
		}
      return convertView;
    }

    // And here is when the "chooser" is popped up
    // Normally is the same view, but you can customize it if you want
    @Override
    public View getDropDownView(int position, View convertView,
            ViewGroup parent) {
    	LayoutInflater inflater = 
	              (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if(convertView == null){
			convertView = inflater.inflate(R.layout.dropdown_item, parent,false);			
		}
		((TextView)convertView).setText(pType.get(position).toString());
        return convertView;
    }

}
